package com.mmy.dao.hotel;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.hotel.THotelPlan;

public interface THotelPlanRepository extends JpaRepository<THotelPlan, Integer> {
	/**
	 * 获取计划单最大值
	 * 
	 * @return 返回值说明 最大计划单编码
	 * @author 创建人 dingxd
	 * @date 创建日期 2020.11.16
	 */
	@Query(value = "SELECT MAX(iPlanID) FROM tHotelPlan WHERE LEFT(iPlanID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxPlanID();

	/* 创建酒店计划 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tHotelPlan(iPlanID, cService, iRoomID, dStartDate, dEndDate, fFloor, fPeer, fPrice, iNumber, cExplain, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, NULL, 0, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int planID);

	/**
	 * 通过计划编码查询
	 * 
	 * @return 返回值说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2021.03.02
	 */
	@Query(value = "select *  from tHotelPlan where iPlanID=?1", nativeQuery = true)
	THotelPlan findByPlanID(int planID);

	/* 删除酒店计划 */
	@Transactional
	@Modifying
	@Query(value = "delete from tHotelPlan where iPlanID in (:lstPlanID)", nativeQuery = true)
	void delHotelPlan(@Param("lstPlanID") List<Integer> lstPlanID);

}
